<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>手机验证码注册页面</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">

    <link rel="stylesheet" href="{{asset('style/weui/css/weui.css')}}"/>
    <link rel="stylesheet" href="{{asset('style/weui/css/weuix.css')}}"/>
    <script src="{{asset('style/weui/js/zepto.min.js')}}"></script>
    <script src="{{asset('style/weui/js/zepto.weui.js')}}"></script>



    <script type="text/javascript">
        var countdown=60;
        function settime(obj){
            //60秒倒计时
            if (countdown == 0){
                obj.removeAttribute("disabled");
                obj.value="发送短信验证码";
                countdown = 60;
                return;
            }else{
                obj.setAttribute("disabled", true);
                obj.value="重新发送(" + countdown + ")";
                countdown--;
            }
            setTimeout(function() {
                    settime(obj) }
                ,1000)
        }

        $(document).ready(function() {
            //清除输入文字信息
            function cleartxt(obj){
                $(obj).prev().find('.weui-input').val("");
                return false;
            };


            //点击发送短信验证码
            $("#yzmfs").click(function () {
                //确保手机号不为空
                var mobile=$("#phone").val();
                if(mobile.length==0)
                {
                    $.toptip('请输入手机号码！');
                    $("#phone").focus();
                    return false;
                }
                if(mobile.length!=11)
                {
                    $.toptip('请输入11位手机号！');
                    $("#phone").focus();
                    return false;
                }
                var myreg = /^((1[3|4|5|8][0-9]{1})+\d{8})$/;
                if(!myreg.test(mobile))
                {
                    $.toptip('请输入正确的手机号码！');
                    document.getElementById("phone").focus();
                    return false;
                }
                //点击发送短信验证码
                $.ajax({
                    async : false,
                    type: "get",
                    url: "{{url('code')}}", //
                    data: {},
                    success: function (data) {
                        //发送短信验证码
                        $("#code").val(data); //获取生成验证码赋值 加密
                        $.ajax({
                            async : false,
                            type: "post",
                            url: "{{url('smsyzm')}}", //
                            data: {
                                "yzm": data,
                                'yzmtel': $('#phone').val(),
                                '_token':'{{csrf_token()}}'
                            },
                            dataType: "json",
                            success: function (data) {
                            }
                        });
                    }
                });

            })
        })


        //注册 ajax提交
        function register(){

            var name = $("#name").val();
            var pwd = $("#pwd").val();
            var pwd_confirmation = $("#pwd_confirmation").val();
            var phone = $("#phone").val();
            var code = $("#code").val();
            var yzm = $("#yzm").val();//手动输入的验证码

            $.post("{{url('register')}}",{
                "name":name,
                "pwd":pwd,
                "pwd_confirmation":pwd_confirmation,
                "phone":phone,
                "code":code,
                "yzm":yzm,
                "_token":"{{csrf_token()}}",
            },function(data,status){
                //$.toptip(data);

                if(data==1){
                    $.toast("注册成功");
                    window.location.href="http://www.lianxiang.com/";
                }else if(data==0){
                    $.toast("注册失败", "forbidden");

                }else{
                    $.toptip(data);
                }
            });
        }



    </script>


</head>
<body>
<form action=""  onsubmit="return false;" id="formRegister">
    {{csrf_field()}}
    <div class="weui-cells weui-cells_form">

        <div class="weui-cell margin5 margin15  border-radius  w">
            <div class="weui-cell__hd">
                <label class="weui-label">用户名</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" placeholder="请输入用户名" type="text" name="name" id="name">
            </div>
            <i class="weui-icon-clear" onclick="cleartxt(this)"></i>
        </div>

        <div class="weui-cell margin5 margin15  border-radius  w">
            <div class="weui-cell__hd">
                <label class="weui-label">密码</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" placeholder="请输入密码" type="password" name="pwd" id="pwd">
            </div>
            <i class="weui-icon-clear" onclick="cleartxt(this)"></i>
        </div>
        <div class="weui-cell margin5 margin15  border-radius  w">
            <div class="weui-cell__hd">
                <label class="weui-label">确认密码</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" placeholder="请重复输入密码" type="password" name="pwd_confirmation" id="pwd_confirmation">
            </div>
            <i class="weui-icon-clear" onclick="cleartxt(this)"></i>
        </div>

        <div class="weui-cell margin5 margin15  border-radius  w">
            <div class="weui-cell__hd">
                <label class="weui-label">手机号</label>
            </div>
            <div class="weui-cell__bd">
                <input class="weui-input" placeholder="请输入手机号" type="number" name="phone" id="phone">
            </div>
            <i class="weui-icon-clear" onclick="cleartxt(this)"></i>
        </div>

        <!--<input id="msg" hidden>-->
        <input id="code" hidden name="code">

        <div class="weui-cell margin5 margin15  border-radius  w">

            <div class="weui-cell__bd">
                <input class="weui-input" type="text" id="yzm" name="yzm">
            </div>
            <i class="weui-icon-clear" onclick="cleartxt(this)"></i>
            <div class="weui-cell__hd">
                <input class="weui-input" type="button" id="yzmfs" value="发送短信验证码" onclick="settime(this)" />
            </div>
        </div>



        <div class="weui-btn-area">
            <input class="weui-btn weui-btn_primary" type="submit" value="注册" onclick="register()">
        </div>

    </div>


</form>
</body>
<script type="text/javascript">


</script>


</html>